<template>
    <Teleport to="#modal">
    <div class="modal d-block d-flex align-items-center justify-content-center " v-if="visible">
        <div class="modal-dialog w-50" tabindex="-1">
            <div class="modal-content ">
                <div class="modal-header">
                    <h5 class="modal-title">{{title}}</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close" @click="onClose"></button>
                </div>
                <div class="modal-body">
                    <slot></slot>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal" @click="onClose">取消</button>
                    <button type="button" class="btn btn-primary" @click="onConfirm">确认</button>
                </div>
            </div>
        </div>
    </div>
    </Teleport>
</template>

<script lang="ts">
import { defineComponent } from 'vue'
import useDOMCreate from '@/hooks/useDOMCreate'
export default defineComponent({
    emits:['model-on-close','model-on-confirm'],
    props:{
        title:String,
        visible:{
            type :Boolean,
            default:false
        }
    },
    setup(props,context) {
        // const isVisible = ref(true)
        useDOMCreate('modal')
        const onClose = ()=>{
            context.emit('model-on-close')
        }
        const onConfirm = ()=>{
            context.emit('model-on-confirm')
        }
        
        return {
            onClose,
            onConfirm
        }
    }
})
</script>

<style scoped></style>
